var pageSize = 5;
function getTableId(){return 'lista-modelos'}

/*criador de linhas*/
function modeloRowCreator(options){
	var cssClass = options.rowNum % 2 == 0? 'row1' : 'row2';
	var tr = document.createElement("tr");
	tr['className'] = cssClass;
	return tr;
}

function loadPage(pageNum, obj){
	ModeloService.getPage(pageNum, pageSize, makeRows);
	$('a.end').css({'border-color':'#CCC'});
	$('a.end:nth-child('+pageNum+')').css({'border-color':'#036'});
}

function makeRows(data){
	var modelos = data.content;
	dwr.util.removeAllRows(getTableId());
	dwr.util.addRows(
			getTableId(), 
			modelos, 
			[
			 function(modelo){return '&nbsp;'},
			 function(modelo){return a(modelo.descricao, 'modelo.html?id=' + modelo.id, []);}
			 ]
			 ,{rowCreator: modeloRowCreator, escapeHtml:false}
	);
	hideLoading();
}

jQuery(function(){
	
	//carrega a lista de modelos. a pagina 1 por default
	showLoading();
	loadPage(1, null);
	
});

jQuery(function(){
	//constroi os links da paginacao
	ModeloService.getPageRange(pageSize, function(data){
		buildPageLinks(data, 'paginator-modelos');
	});	
});